package controllers

import (
	"encoding/json"
	"ltbz/cultural_tourism_api/models"
	"ltbz/cultural_tourism_api/models/system"

	systemServices "ltbz/cultural_tourism_api/services/system"
)

type AuthController struct {
	BaseUnAuthController
}

// @Title 登陆
// @Description 登陆
// @Param	request	body system.LoginReq true "type json string"
// @Success 200
// @router /login [post]
func (this *AuthController) Login() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()

	req := new(system.LoginReq)
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
	if err != nil {
		br.Msg = "参数解析异常！"
		br.ErrMsg = "参数解析失败，Err:" + err.Error()
		return
	}
	ret, err, errMsg := systemServices.Login(req.SysUserName, req.Password)
	if err != nil {
		br.Msg = "登陆失败！"
		br.ErrMsg = "登陆失败，Err:" + err.Error() + ";errMsg:" + errMsg
		return
	}
	br.Ret = 200
	br.Msg = "登陆成功"
	br.Data = ret
	return
}
